/**
 * 
 */
package leetCode;

import java.util.HashMap;

/**
 * @author zhongfang
 *
 */
public class RansomNote {
    public boolean canConstruct(String ransomNote, String magazine) {
    	HashMap<Character, Integer> frequency=new HashMap<>(magazine.length());
    	for (int i = 0; i < magazine.length(); i++) {
			char a=magazine.charAt(i);
			frequency.merge(a, 1, (x,y)->(x+1));
		}
    	for (int i = 0; i < ransomNote.length(); i++) {
			char a=ransomNote.charAt(i);
			if(!frequency.containsKey(a)||frequency.get(a)==0){
				return false;
			}
			frequency.put(a, frequency.get(a)-1);
		}
    	return true;
    }
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String string="";
		StringBuilder sBuilder=new StringBuilder(3);
	}

}
